<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('商户信息列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label style="width: 80px;">商户编号：</label>
                            <input type="text" name="merno"/>
                        </li>
                        <li>
                            <label style="width: 80px;">渠道商户号：</label>
                            <input type="text" name="ldMerno"/>
                        </li>
                        <li>
                            <label style="width: 80px;">机器号：</label>
                            <input type="text" name="sn"/>
                        </li>
                        <li>
                            <label style="width: 80px;">商户名称：</label>
                            <input type="text" name="merName"/>
                        </li>
                        <li>
                            <label style="width: 80px;">服务商编号：</label>
                            <input type="text" name="agentNo"/>
                        </li>
                        <li>
                            <label style="width: 80px;">服务商名称：</label>
                            <input type="text" name="agentInfo.agentName"/>
                        </li>
                        <li>
                            <label style="width: 80px;">手机号：</label>
                            <input type="text" name="linkPhone" placeholder="精确搜索"/>
                        </li>
                        <li>
                            <label style="width: 80px;">商户状态：</label>
                            <select name="merStatus" th:with="type=${@dict.getType('mer_status')}">
                                <option value="">请选择</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label style="width: 80px;">商户类型：</label>
                            <select name="merType" th:with="type=${@dict.getType('mer_type')}">
                                <option value="">请选择</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label style="width: 80px;">商户渠道：</label>
                            <select name="merTb" th:with="type=${@dict.getType('mer_tb')}">
                                <option value="">请选择</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>

                        <li>
                            <label style="width: 80px;">结算人名：</label>
                            <input type="text" name="accounts.screenName"/>
                        </li>

                        <li>
                            <label style="width: 80px;">身份证号：</label>
                            <input type="text" name="legalCerno" placeholder="精确搜索"/>
                        </li>
                        <li>
                            <label style="width: 80px;">结算周期：</label>
                            <select name="settleCycle">
                                <option value="">所有</option>
                                <option value="0">D0</option>
                                <option value="1">T1</option>
                            </select>
                        </li>
                        <li class="select-time">
                            <label style="width: 80px;">添加日期：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginAddDate]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endAddDate]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success single disabled" onclick="merMigrate()"
               shiro:hasPermission="merchantInfo:merchantInfo:merMigrate">
                <i class="fa fa-edit"></i> 商户迁移
            </a>
            <a class="btn btn-success single disabled" onclick="bangding()"
               shiro:hasPermission="merchantInfo:merchantInfo:bangding">
                <i class="fa fa-edit"></i> 终端绑定
            </a>
            <a class="btn btn-success single disabled" onclick="posPush()"
               shiro:hasPermission="merchantInfo:merchantInfo:posPush">
                <i class="fa fa-edit"></i> 终端推送
            </a>
            <a class="btn btn-success single disabled" onclick="expiry()"
               shiro:hasPermission="merchantInfo:merchantInfo:expiry">
                <i class="fa fa-edit"></i> 有效期变更
            </a>
            <a class="btn btn-success single disabled" onclick="editMerRate()"
               shiro:hasPermission="merchantInfo:merchantInfo:editMerRate">
                <i class="fa fa-edit"></i> 修改费率
            </a>
            <a class="btn btn-success single disabled" onclick="getMerDetails()"
               shiro:hasPermission="merchantInfo:merchantInfo:getMerDetails">
                <i class="fa fa-edit"></i> 商户详情
            </a>
            <!-- <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="merchantInfo:merchantInfo:export">
                 <i class="fa fa-download"></i> 导出
             </a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" class="table text-nowrap"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('merchantInfo:merchantInfo:edit')}]];
    var removeFlag = [[${@permission.hasPermi('merchantInfo:merchantInfo:remove')}]];
    var lookInfoFlag = [[${@permission.hasPermi('merchantInfo:merchantInfo:lookInfo')}]];
    var prefix = ctx + "merchantInfo/merchantInfo";
    var merType = [[${@dict.getType('mer_type')}]];
    var merStatus = [[${@dict.getType('mer_status')}]];
    var merTb = [[${@dict.getType('mer_tb')}]];
    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "商户信息",
            clickToSelect: true,
            columns: [{
                radio: true
            },
                {
                    field: 'merno',
                    title: '商户编号',
                },
                {
                    field: 'ldMerno',
                    title: '渠道商户号'
                },
                {
                    field: 'merTb',
                    title: '商户渠道',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(merTb, value);
                    }
                },
                {
                    field: 'merName',
                    title: '商户名称'
                },
                /* {
                     field: 'merLevel',
                     title: '商户等级',
                     formatter:function (value, row, index) {
                         return $.table.tooltip(value,3);
                     }
                 },*/
                {
                    field: 'merNature',
                    title: '商户性质',
                    align: 'center',
                    formatter: function (value, row, index) {
                        if ("0" == value) {
                            return "企业";
                        } else if ("1" == value) {
                            return "个人";
                        } else if ("3" == value) {
                            return "Mpos个人";
                        } else if ("4" == value) {
                            return "Mpos企业";
                        } else if ("5" == value) {
                            return "大Pos个人";
                        } else if ("6" == value) {
                            return "大Pos企业";
                        } else {
                            return "无";
                        }
                    }
                },
                {
                    field: 'settleStatus',
                    title: '冻结状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        if ("0" == value) {
                            return "正常";
                        } else if ("-1" == value) {
                            return "冻结";
                        } else if ("1" == value) {
                            return "自动";
                        } else {
                            return "未知";
                        }
                    }
                },
                /*  {
                      field: 'merDqType',
                      title: '电签标识',
                      formatter:function (value, row, index) {
                          if ("A"==value){
                              return "电签9号";
                          }else if("B"==value){
                              return "电签5号";
                          }else{
                              return "无";
                          }
                      }
                  },*/
                {
                    field: 'accounts.screenName',
                    title: '结算人'
                },
                {
                    field: 'merArea',
                    title: '商户地区',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 3);
                    }
                },
                {
                    field: 'merAddress',
                    title: '详细地址',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 3);
                    }
                },
                {
                    field: 'showLegalcerno',
                    title: '展示身份证号'
                },
                {
                    field: 'showLinkphone',
                    title: '展示手机号'
                },
                {
                    field: 'merType',
                    title: '商户类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(merType, value);
                    }
                },
                {
                    field: 'merStatus',
                    title: '商户状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(merStatus, value);
                    }
                },
                {
                    field: 'merMsg',
                    title: '状态描述'
                },
                {
                    field: 'agentNo',
                    title: '服务商编号'
                },
                {
                    field: 'agentInfo.agentName',
                    title: '服务商名称'
                },
                /* {
                     field: 'settleCycle',
                     title: '结算周期',
                     formatter:function (value, row, index) {
                         if ("0"==value){
                             return "D0";
                         }else if("1"==value){
                             return "T1";
                         }else{
                             return "无";
                         }
                     }
                 },*/
                {
                    field: 'note',
                    title: '备注',
                    width: 60,
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 2);
                    }
                },
                {
                    field: 'addDate',
                    title: '添加日期'
                },
                {
                    field: 'addTime',
                    title: '添加时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + lookInfoFlag + '" href="javascript:void(0)" onclick="lookInfo(\'' + row.merno + '\')"><i class="fa fa-plus"></i>查看详情</a> ');
                        return actions.join('');
                    }
                },]
        };
        $.table.init(options);
    });

    function userRecord() {
        var merNo = $.table.selectColumns("merno")
        if ($.common.isEmpty(merNo)) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        $.modal.openTab("用户行为记录", prefix + '/userRecord/' + merNo);
    }

    function lookImg() {
        var merNo = $.table.selectColumns("merno")
        if ($.common.isEmpty(merNo)) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        // $.modal.open("查看图片", prefix + '/lookImg/' + merNo, '1200');

        //如果是移动端，就使用自适应大小弹窗
        var width = 1000;
        var height = $(window).height() - 50;
        if ($.common.isMobile()) {
            width = 'auto';
            height = 'auto';
        }
        var url = prefix + '/lookImg/' + merNo;
        //$.modal.open("商品详情", url,width, height);
        var btn = ['关闭'];
        var options = {
            title: '查看图片',
            width: width,
            height: height,
            url: url,
            btn: btn,
            yes: function (index) {
                layer.close(index);
            }
        };
        $.modal.openOptions(options);
    }

    function cancelMer() {
        var merNo = $.table.selectColumns("merno")
        if ($.common.isEmpty(merNo)) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        $.modal.open("注销商户", prefix + "/cancelMer/" + merNo, '800', '350');
    }

    function updateAddress() {
        var merNo = $.table.selectColumns("merno")
        if ($.common.isEmpty(merNo)) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        $.modal.open("修改注册地址", prefix + "/updateAddress/" + merNo, '800', '400');
    }

    function updateBank() {

        var merNo = $.table.selectColumns("merno");
        if ($.common.isEmpty(merNo)) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var selectMerStatus = $.table.selectColumns("merStatus");
        if (0 != selectMerStatus && 0 != selectMerStatus && 9 != selectMerStatus) {
            $.modal.alertWarning("请选择人脸,正式,停用的商户");
            return;
        }
        $.modal.open("修改结算银行", prefix + "/updateBank/" + merNo, '1200', '600');
    }

    function updateSettle() {
        var merNo = $.table.selectColumns("merno")
        if ($.common.isEmpty(merNo)) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var merType = $.table.selectColumns("merType");
        var merNature = $.table.selectColumns("merNature");
        if (0 != merType && 1 != merNature) {
            $.modal.alertWarning("不是传统个人商户，不可修改");
            return;
        }
        $.modal.open("修改结算类型", prefix + "/updateSettle/" + merNo, '800', '300');
    }

    /**
     * 商户解冻/冻结
     * */
    function updateFreeze() {
        var merNo = $.table.selectColumns("merno")
        if ($.common.isEmpty(merNo)) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        $.modal.open("修改商户冻结状态", prefix + "/updateFreeze/" + merNo, '800', '300');
    }

    function lookInfo(merNo) {
        //$.modal.open("查看商户资料", prefix + '/enterpriseInfo?merNo=' + merNo,'1000');
        //如果是移动端，就使用自适应大小弹窗
        var width = 1000;
        var height = $(window).height() - 50;
        if ($.common.isMobile()) {
            width = 'auto';
            height = 'auto';
        }
        var url = prefix + '/enterpriseInfo?merNo=' + merNo;
        //$.modal.open("商品详情", url,width, height);
        var btn = ['关闭'];
        var options = {
            title: '查看商户资料',
            width: width,
            height: height,
            url: url,
            btn: btn,
            yes: function (index) {
                layer.close(index);
            }
        };
        $.modal.openOptions(options);
    }


    /**
     * 查看手机号
     * */
    function findPhone() {
        var merNo = $.table.selectColumns("merno")
        if ($.common.isEmpty(merNo)) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        //如果是移动端，就使用自适应大小弹窗
        var width = 800;
        var height = 450;
        if ($.common.isMobile()) {
            width = 'auto';
            height = 'auto';
        }
        var url = prefix + "/findPhone?merNo=" + merNo;
        var btn = ['关闭'];
        var options = {
            title: '查看手机号',
            width: width,
            height: height,
            url: url,
            btn: btn,
            yes: function (index) {
                layer.close(index);
            }
        };
        $.modal.openOptions(options);
    }

    /**
     * 查看商户最新信息
     * */
    function showMerchantNewInfo() {
        var merNo = $.table.selectColumns("merno")

        if ($.common.isEmpty(merNo)) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        //如果是移动端，就使用自适应大小弹窗
        var width = 1300;
        var height = 600;
        if ($.common.isMobile()) {
            width = 'auto';
            height = 'auto';
        }
        var url = prefix + "/newMerchantInfo?merno=" + merNo;
        var btn = ['关闭'];
        var options = {
            title: '查看商户最新信息',
            width: width,
            height: height,
            url: url,
            btn: btn,
            yes: function (index) {
                layer.close(index);
            }
        };
        $.modal.openOptions(options);
    }


    /**
     * 商户迁移
     */
    function merMigrate() {
        //商户编号
        var merNo = $.table.selectColumns("merno");
        $.modal.open("商户迁移", prefix + "/merMigrate?merNo=" + merNo, '1100', '800');
    }

    /**
     * 新商户迁移
     */
    function newMerMigrate() {
        //商户编号
        var merNo = $.table.selectColumns("merno");
        $.modal.open("新商户迁移", prefix + "/newMerMigrate?merNo=" + merNo, '1100', '800');
    }

    /**
     * 绑定终端
     */
    function bangding() {
        //商户编号
        var merNo = $.table.selectColumns("merno");
        $.modal.open("绑定终端", prefix + "/bangding?merNo=" + merNo, '800', '400');
    }

    function posPush() {
        //商户编号
        var merNo = $.table.selectColumns("merno");
        $.modal.open("终端推送", prefix + "/posPush?merNo=" + merNo, '800', '450');
    }

    function expiry() {
        //商户编号
        var merNo = $.table.selectColumns("merno");
        $.modal.open("终端推送", prefix + "/expiry?merNo=" + merNo, '800', '450');
    }

    /**
     * 修改费率
     */
    function editMerRate() {
        //商户编号
        var merNo = $.table.selectColumns("merno");
        $.modal.open("修改费率", prefix + "/editMerRate?merno=" + merNo, '1100', '800');
    }

    /**
     * 商户详情
     */
    function getMerDetails() {
        //商户编号
        var merNo = $.table.selectColumns("merno");
        $.modal.open("商户详情", prefix + "/getMerDetails?merNo=" + merNo, '1100', '800');
    }

    /**
     * 商户换机
     */
    function merReplacePos() {
        //商户编号
        var merNo = $.table.selectColumns("merno");
        $.modal.open("商户换机", prefix + "/merReplacePos?merNo=" + merNo, '1100', '800');
    }

    /**
     * 商户换机GB
     */
    function merReplacePosGB() {
        //商户编号
        var merNo = $.table.selectColumns("merno");
        $.modal.open("商户GB换机", prefix + "/merReplacePosGB?merNo=" + merNo, '1100', '800');
    }

    function merSync() {
        var merno = $.table.selectColumns("merno")[0];
        $.modal.confirm("确认要同步吗", function () {
            var url = prefix + "/merSyn";
            var data = {"merno": merno};
            $.operate.post(url, data);
        });
    }

    function merMesSync() {

        var merNo = $.table.selectColumns("merno");
        if ($.common.isEmpty(merNo)) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var selectMerStatus = $.table.selectColumns("merStatus");
        if (0 != selectMerStatus && 0 != selectMerStatus && 9 != selectMerStatus) {
            $.modal.alertWarning("请选择人脸,正式,停用的商户");
            return;
        }
        $.modal.open("商户信息同步", prefix + "/updateMerMes/" + merNo, '1200', '600');
    }

    /**
     * 转为问题商户
     */
    function merProblem() {
        var merno = $.table.selectColumns("merno")[0];
        var status = $.table.selectColumns("merStatus")[0];
        if (status == '0' || status == '1') {
            $.modal.alertWarning("正式,停用的商户无法人工审核");
            return
        }
        $.modal.confirm("确认要进行人工审核吗", function () {
            var url = prefix + "/merProblem";
            var data = {"merno": merno};
            $.operate.post(url, data);
        });
    }

    /**
     * 变更商户状态
     */
    function updateMerStatus() {
        var merno = $.table.selectColumns("merno")[0];
        var status = $.table.selectColumns("merStatus")[0];
        if (status == '0') {
            $.modal.alertWarning("已是正式商户，无法变更");
            return
        }
        $.modal.confirm("确认要变更商户状态吗？", function () {
            var url = prefix + "/updateMerSta";
            var data = {"merno": merno};
            $.operate.post(url, data);
        });
    }

</script>
</body>
</html>
